package com.qianyu.project.service.impl;


import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qianyu.project.core.annotation.FlowBegin;
import com.qianyu.project.core.annotation.FlowEntry;
import com.qianyu.project.core.bean.FundEssentialinformation;
import com.qianyu.project.core.bean.FundPlanDetail;
import com.qianyu.project.mapper.ExpendFundPlanMapper;
import com.qianyu.project.mapper.TenderPurchasePlanMapper;
import com.qianyu.project.service.IExpendFundPlanService;
import com.qianyu.project.service.IFundPlanDetailService;
import com.qianyu.project.service.ITenderPurchaseDetailService;
import com.qianyu.project.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @author:xz
 * @Date: Created in 2021/2/11 15:56
 */
@Service
public class ExpendFundPlanServiceImpl extends ServiceImpl<ExpendFundPlanMapper, FundEssentialinformation> implements IExpendFundPlanService {

    @Autowired
    private ExpendFundPlanMapper expendFundPlanMapper;
    @Autowired
    private IFundPlanDetailService fundPlanDetailService;



    @Transactional(rollbackFor = Exception.class)
    @FlowBegin("fund_essentialinformation")
    @Override
    public Integer saveWithDetails(@FlowEntry("id") FundEssentialinformation expendFundPlanjbxx, List<FundPlanDetail> expendFundPlanmx) {
        expendFundPlanjbxx.setApproveStatus(1);
        expendFundPlanMapper.insert(expendFundPlanjbxx);
        //保存详情
        fundPlanDetailService.saveBatch(expendFundPlanmx);
        //返回模块id做流程
        return 1;
    }

    @Override
    public IPage<FundEssentialinformation> getPageList(Map<String, String> params) {
        return expendFundPlanMapper.selectPageList(PageUtil.createPage(params),params);
    }

    @Override
    public String getMaxCode() {
        String code = expendFundPlanMapper.selectMaxCode();
        if(code == null){
            code = DateUtil.today().replaceAll("-", "") + "000";
        }
        return code;
    }

    @Override
    public void del(String id) {
        expendFundPlanMapper.del(id);
    }
}
